import { getAreaObj } from '@/utils/util'
let apprStatus = [
	{label:"全部",value:''},
	{label:"办理中",value:"0",type:"primary"},
	{label:"通过",value:"1",type:"success"},
	{label:"驳回",value:"-1",type:"danger"}
]

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{
			label: '服务对象',
			prop: 'oldmanName',
		},
		{
			label: '申请人姓名',
			prop: 'createUserName',
		},
		{
			label: '身份证号',
			prop: 'idCard',
		},
		{
			label: '手机号码',
			prop: 'oldmanPhone',
		},
		{
			label: '户籍地区',
			prop: 'crAddr',
		},
		{
			label: '现居地区',
			prop: 'addr',
		},
		{
			label: '申请时间',
			prop: 'createTime',
		},
		{
			label: '申请状态',
			prop: 'processStatus',
			custome: 'tag',
			dicData:apprStatus
		},
		{
			label: '评估结果',
			prop: 'estimateResultLabel',
		},
		{
			label: '改造状态',
			prop: 'transformResultLabel',
		},
		{
			label: '验收状态',
			prop: 'checkResultLabel',
		},
		// {
		// 	label: '审批状态',
		// 	prop: 'processStatus',
		// 	custome: 'tag',
		// 	dicData:apprStatus
		// },
		{
			label: '上链状态',
			prop: 'onBlockchainFlag',
			api: 'geiDictItemList',
			type: 'select',
			custome: 'tag',
			code: 'BLOCK_CHAIN_STATUS',
			defaultValue: '1',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

const searchConfig = {
	inline: true,
	column: [
		{
			label: '申请人姓名',
			prop: 'createUserName',
			type: 'input',
			span: 8,
		},
		{
			label: '身份证号',
			prop: 'idCard',
			type: 'input',
			span: 8,
		},
		{
			label: '手机号码',
			prop: 'oldmanPhone',
			type: 'input',
			span: 8,
		},
		{
			label: '户籍地区',
			prop: 'cr_areas',
			propName: 'cr_areas_name',
			regionGrade: 3,
			checkStrictly: false,
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '现居地区',
			prop: 'areas',
			propName: 'areas_name',
			regionGrade: 3,
			checkStrictly: false,
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '申请时间',
			prop: 'createTimeBetween',
			type: 'datetimerange',
			format: 'YYYY年MM月DD HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
		{
			label: '申请状态',
			type:"select",
			prop: 'processStatus',
			propName:"processStatusLabel",
			dicData:apprStatus,
			span: 8,
		},
	],
}

export const processStatusConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		{
			label: '申请审核状态',
			prop: 'processStatus',
			propName: 'processStatusLabel',
			type: 'radio',
			dicData: [
				{
					label: '通过',
					value: '1',
				},
				{
					label: '驳回',
					value: '-1',
				},
			],
			span: 24,
			control: (e, model) => {
				return {
					processNote: {
						display: e == -1,
					},
				}
			},
			rules: [
				{
					required: true,
					message: '请选择申请审核状态',
					trigger: 'change',
				},
			],
		},
		{
			label: '驳回原因',
			prop: 'processNote',
			type: 'textarea',
			maxlength: '140',
			span: 24,
			showWordLimit: true,
		},
	],
}
export const estimateResultConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		{
			label: '评估结果',
			prop: 'estimateResult',
			propName: 'estimateResultLabel',
			type: 'radio',
			dicData: [
				{
					label: '未完成',
					value: '1',
				},
				{
					label: '评估中',
					value: '2',
				},
				{
					label: '已完成',
					value: '3',
				},
			],
			span: 24,
			rules: [
				{
					required: true,
					message: '请选择评估结果',
					trigger: 'change',
				},
			],
		},
	],
}
export const transformResultConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		{
			label: '改造状态',
			prop: 'transformResult',
			propName: 'transformResultLabel',
			type: 'radio',
			dicData: [
				{
					label: '未完成',
					value: '1',
				},
				{
					label: '改造中',
					value: '2',
				},
				{
					label: '已完成',
					value: '3',
				},
			],
			span: 24,
			rules: [
				{
					required: true,
					message: '请选择改造状态',
					trigger: 'change',
				},
			],
		},
	],
}
export const checkResultConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'right',
	labelWidth: '120px',
	column: [
		{
			label: '验收状态',
			prop: 'checkResult',
			propName: 'checkResultLabel',
			type: 'radio',
			dicData: [
				{
					label: '未验收',
					value: '1',
				},
				{
					label: '验收中',
					value: '2',
				},
				{
					label: '已验收',
					value: '3',
				},
			],
			span: 24,
			rules: [
				{
					required: true,
					message: '请选择验收状态',
					trigger: 'change',
				},
			],
		},
	],
}

export const baseConfig: any = {
	pageName: '业务办理管理',
	addLabel: '',
	dictcodes: ['BUSINESSTYPE', 'BLOCK_CHAIN_STATUS'],
	rowKey: 'processCode',
	// tipLabel: 'projectName',
	api: {
		index: 'view_bscBusinessProcess_page',
		// add: 'view_ofsSubsidyApply_add',
		// export: 'view_ofsSubsidyApply_approval_exportApply'
		// 	edit: 'view_ofsSubsidyProject_edit',
		// 	delete: 'view_ofsSubsidyProject_del',
		detail: 'view_bscBusinessProcessLog_list',
	},
	auth: {
		index: 'view_bscBusinessProcess_page',
		// add: 'view_ofsSubsidyApply_add',
		// mulitSet: 'view_ofsSubsidyApply_approval_exportApply'
		// 	edit: 'view_ofsSubsidyProject_edit',
		// 	delete: 'view_ofsSubsidyProject_del',
		detail: 'view_bscBusinessProcessLog_list',
	},

	menuBtn: [
		{
			icon: '',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: 'view_ofsSubsidyApply_view',
			text: true,
			show: true,
		},
		{
			icon: '',
			label: '查看审核表',
			type: 'primary',
			operate: 'tableReport',
			auth: 'view_ofsSubsidyApply_view',
			condition: "(row)=>row.businessType=='4'",
			text: true,
			show: true,
		},
		{
			icon: '',
			label: '审批',
			type: 'primary',
			operate: 'examine',
			auth: 'view_bscBusinessProcess_edit',
			// condition: "(row)=>row.processStatus=='-1'||row.checkResult!='3'",
			condition: "(row)=>row.processStatus == '-1'||row.processStatus == '1' ? false : row.checkResult == '3' ? false : true",
			text: true,
			show: true,
		},
		// {
		// 	icon: '',
		// 	label: '撤销申请',
		// 	type: 'primary',
		// 	operate: 'cancel',
		// 	auth: 'view_workflowApprovalLogic_revocation',
		// 	text: true,
		// 	show: true,
		// }
	],
	// dialogConfig: {
	// 	width: '65%',
	// },
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			item.crAddr = item.crProvinceName + item.crCityName + item.crAreaName
			item.addr = item.provinceName + item.cityName + item.areaName
			return {
				...item,
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	beforeOnLoadFormate: async (query) => {
		let crAreasObj = getAreaObj(query.cr_areas, 'cr')
		let crAreasNameObj = getAreaObj(query.cr_areas_name, 'cr')
		let areasObj = getAreaObj(query.areas)
		let areasNameObj = getAreaObj(query.areas_name)
		if (query.createTimeBetween) {
			query.createTimeBetween = query.createTimeBetween.join(',')
		}
		return new Promise((resolve, reject) => {
			resolve({
				...query,
				...crAreasObj,
				...areasObj,
				...crAreasNameObj,
				...areasNameObj,
				cr_areas: undefined,
				areas: undefined,
				cr_areas_name: undefined,
				areas_name: undefined,
			})
		})
	},
	searchConfig,
	tableConfig,
	// detailConfig,
}
